<?php
require 'Model.php';

class HouseModel extends Model
{
    function __construct()
    {
        parent::__construct();
    }

    function addhouse(){
        $type = $_POST['type'];
        $housetype=$_POST['housetype'];
        $builddate=$_POST['builddate'];
        $address=$_POST['address'];
        $area=$_POST['area'];
        $floor=$_POST['floor'];
        $allfloor=$_POST['allfloor'];
        $region=$_POST['region'];
        $price=$_POST['price'];
        $rent=$_POST['rent'];
        $contact=$_POST['contact'];
        $tel=$_POST['tel'];
        $demo=$_POST['demo'];
        if(!empty($_FILES["pic"]["name"])){
            $pic = parent::uploadfile('pic');
        }
        else{
            $pic='';
        }
        $sql = "insert into house values
        (null,'$type','$address','$builddate','$area','$housetype','$floor','$allfloor','$region','$price','$rent',
        '$contact','$tel','$demo','0','$pic',NULL)";
        $result=$this->conn->query($sql);
        return $result;
    }

    function getHouseList(){
        $sql = "select * from house";
        $data = $this->conn->query($sql);

        return $data;
    }

    function getbuyerhouselist($uid){
        $sql = "select * from house where uid = '$uid'";
        $data = $this->conn->query($sql);

        return $data;
    }

    function getHouse($id){
        $sql = "select * from house where id = '$id'";

        $result = $this->conn->query($sql);

        return $result;
    }

    function getuserinfro($key){
        $sql = "select * from house where housetype like '%".$key."%'";
        $data = $this->conn->query($sql);

        return $data;
    }

    function changestatus1($hid){
        $sql = "update house set issale = '1' where id = '$hid'";
        $result = $this->conn->query($sql);

        return $result;
    }

    function changestatus2($hid){
        $sql = "update house set issale = '3' where id = '$hid'";
        $result = $this->conn->query($sql);

        return $result;
    }

    function getUidByUname($uname){
        $sql = "select uid from user where uname = '$uname'";
        $result = $this->conn->query($sql);
        $uid = $result['uid'];

        return $uid;
    }

    function dodeletehouse($id){
        $sql = "delete from house where id = '$id'";
        $result = $this->conn->query($sql);

        return $result;
    }

    function dohousemod($id){
        $type = $_POST['type'];
        $housetype = $_POST['housetype'];
        $address = $_POST['address'];
        $builddate = $_POST['builddate'];
        $floor = $_POST['floor'];
        $allfloor = $_POST['allfloor'];
        $region = $_POST['region'];
        $price = $_POST['price'];
        $rent = $_POST['rent'];
        $demo = $_POST['demo'];
        if(!empty($_FILES["pic"]["name"])){
            $pic = parent::uploadfile('pic');
        }
        else{
            $pic = '';
        }

        $sql = "update house set type = '$type', housetype = '$housetype', address = '$address', builddate = '$builddate', floor = '$floor', allfloor = '$allfloor', region = '$region', price = '$price', rent = '$rent', demo = '$demo', pic = '$pic' where id ='$id'";
        $result = $this->conn->query($sql);

        return $result;
    }
}
?>